package com.koron.order.risk.base.service.impl;


import cn.hutool.core.collection.CollUtil;
import com.koron.order.risk.base.bean.po.LineRiskDetailConstruction;
import com.koron.order.risk.base.mapper.LineRiskDetailConstructionMapper;
import com.koron.order.risk.base.service.LineRiskDetailConstructionService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;

/**
 * 风险管控单-风险详情-施工作业区(LineRiskDetailConstruction)表服务实现类
 *
 * @author jzp
 * @since 2022-12-15 16:17:59
 */
@Service
public class LineRiskDetailConstructionServiceImpl implements LineRiskDetailConstructionService {

    /**
     * 通过ID查询单条数据
     *
     */
    @Override
    @TaskAnnotation("getById")
    public LineRiskDetailConstruction getById(SessionFactory factory, String id) {
        LineRiskDetailConstructionMapper mapper = factory.getMapper(LineRiskDetailConstructionMapper.class);
        return mapper.selectById(id);
    }

    @Override
    @TaskAnnotation("getOneByRiskId")
    public LineRiskDetailConstruction getOneByRiskId(SessionFactory factory, String riskId) {
        LineRiskDetailConstruction lineRiskDetailConstruction = new LineRiskDetailConstruction();
        lineRiskDetailConstruction.setRiskId(riskId);
        List<LineRiskDetailConstruction> list = list(factory, lineRiskDetailConstruction);
        return CollUtil.isEmpty(list) ? null : list.stream().max(Comparator.comparing(LineRiskDetailConstruction::getId)).orElse(null);
    }

    /**
     * 查询所有数据
     *
     */
    @Override
    @TaskAnnotation("list")
    public List<LineRiskDetailConstruction> list(SessionFactory factory, LineRiskDetailConstruction lineRiskDetailConstruction) {
        LineRiskDetailConstructionMapper mapper = factory.getMapper(LineRiskDetailConstructionMapper.class);
        return mapper.selectList(lineRiskDetailConstruction);
    }

    /**
     * 新增数据
     *
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, LineRiskDetailConstruction lineRiskDetailConstruction) {
        LineRiskDetailConstructionMapper mapper = factory.getMapper(LineRiskDetailConstructionMapper.class);
        return mapper.insertOrUpdate(lineRiskDetailConstruction) > 0;
    }

    /**
     * 修改数据
     *
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, LineRiskDetailConstruction lineRiskDetailConstruction) {
        LineRiskDetailConstructionMapper mapper = factory.getMapper(LineRiskDetailConstructionMapper.class);
        return mapper.update(lineRiskDetailConstruction) > 0;
    }

    /**
     * 通过主键删除数据
     *
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        LineRiskDetailConstructionMapper mapper = factory.getMapper(LineRiskDetailConstructionMapper.class);
        return mapper.hidden(id) > 0;
    }
}
